//
//  GLView.swift
//  GLWeiBo
//
//  Created by mac on 16/5/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit
class GLView: UIView {
    //init方法：重写
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    //不同控制器的Label显示
    func setupInfo(message: String, imageName: String? = nil) {
        mesageLabel.text = message
        guard let imageName = imageName else{
            startAnimation()
            return
        }
        //iconView.hidden = true
        homeIconView.hidden = true
        iconView.image = UIImage(named: imageName)
    }
    private func startAnimation() {
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        animation.toValue = 2 * M_PI
        animation.duration = 20
        animation.repeatCount = MAXFLOAT
        animation.removedOnCompletion = false
        iconView.layer.addAnimation(animation, forKey: "animation")
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    ///MARK: - 私有控件
    //图标图片
    private lazy var iconView: UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    //图片标视图
    private lazy var maskIconView: UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
     //小房子图标
    private lazy var homeIconView: UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    //描述文字
    private lazy var mesageLabel: UILabel = UILabel(text: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜", fontSize: 14, TextColr: UIColor.blackColor())
    //注册按钮
    lazy var regesterButton: UIButton = UIButton(
        title: "注册",
        titleColor: UIColor.orangeColor(),
        fontSize: 14,
        imageName: nil,
        backgroundImageName: "common_button_white_disable")
    //登录按钮
    lazy var loginButton: UIButton = UIButton(
        title: "登录",
        titleColor: UIColor.blackColor(),
        fontSize: 14,
        imageName: nil,
        backgroundImageName: "common_button_white_disable")

}
//MARK: - 设置界面
extension GLView {
    private func setupUI() {
        //1.添加控件
        addSubview(iconView)
        addSubview(maskIconView)
        addSubview(mesageLabel)
        addSubview(homeIconView)
        addSubview(regesterButton)
        addSubview(loginButton)
        
        mesageLabel.textAlignment = NSTextAlignment.Center
        //2.自动布局
        //VFL:设置居中非常麻烦
        //苹果原声的自动布局
        for v in subviews {
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        //苹果原生的布局
        iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self)
            make.centerY.equalTo(self)
        }
        homeIconView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        mesageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView)
            make.top.equalTo(iconView.snp_bottom).offset(12)
            make.size.equalTo(CGSize(width: 224, height: 36))

        }
        regesterButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(mesageLabel)
            make.top.equalTo(mesageLabel.snp_bottom).offset(12)
            make.size.equalTo(CGSize(width: 100, height: 36))
        }
        loginButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(mesageLabel)
            make.top.equalTo(mesageLabel.snp_bottom).offset(12)
            make.size.equalTo(regesterButton)
            
        }
        maskIconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self)
            make.right.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(regesterButton)
        }
        
    }
    
}